package com.cxh.controller.Thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test {
	public static void main(String[] args) {
		ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 200, 200,  TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(5));
		long beginTime = System.currentTimeMillis();
		
		for (int i = 0; i < 2; i++) {
			threadPoolExecutor.execute(new MyThread());
		}
		
		threadPoolExecutor.shutdown();
		
		/*try {
			boolean loop = true;
			do {    //等待所有任务完成
				loop = !threadPoolExecutor.awaitTermination(2, TimeUnit.SECONDS);  //阻塞，直到线程池里所有任务结束
			} while(loop);
			System.out.println("线程执行时间为"+(System.currentTimeMillis() - beginTime));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}*/
		
		long num = 1;
		long beginTime2 = System.currentTimeMillis();
		for (long i = 0; i <= 10000000l; i++) {
			if(num < 10000000l){
				num++;
			}
		}
		System.out.println("单线程执行时间为"+(System.currentTimeMillis() - beginTime2));
	}
	
	/*public static void main(String[] args) {
		long num = 1;
		long beginTime = System.currentTimeMillis();
		for (long i = 0; i < 10000000000l; i++) {
			num++;
		}
		System.out.println("执行时间为"+(System.currentTimeMillis() - beginTime));
	}*/
}
